package org.rk.core.ueditor.upload;

import java.io.InputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import org.rk.core.ueditor.define.State;

public class Uploader {
	private HttpServletRequest request = null;
	private Map<String, Object> conf = null;
	private InputStream inputStream=null;
	private String originFileName="";

	public Uploader(HttpServletRequest request, Map<String, Object> conf) {
		this.request = request;
		this.conf = conf;
	}
	public Uploader(InputStream inputStream,String originFileNam, Map<String, Object> conf) {
		this.inputStream = inputStream;
		this.originFileName = originFileNam;
		this.conf = conf;
	}

	public final State doExec() {
		State state = null;

		if ("true".equals(this.conf.get("isBase64"))) {
			state = Base64Uploader.save(this.request,this.conf);
		} else {
			state = BinaryUploader.save(this.request,this.conf);
		}

		return state;
	}
	public final State doExecV2() {
		State state = null;

		if ("true".equals(this.conf.get("isBase64"))) {
			state = Base64Uploader.save(this.request,this.conf);
		} else {
			state = BinaryUploader.save(this.inputStream,this.originFileName, this.conf);
		}

		return state;
	}
}
